package com.tql.test_04;

import java.util.concurrent.CountDownLatch;

/*
    CountDownLatch 线程减少
     countDownLatch.countDown();//减一
     countDownLatch.await();//等待计数器归零，在执行后面操作
* */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        //初始化线程数量
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"go out");
                countDownLatch.countDown();//减一
            },String.valueOf(i)).start();
        }
        countDownLatch.await();//等待计数器归零，在执行后面操作
        System.out.println("close door");
    }
}
